import { useContext } from "react";
import { DesignFrameworkContext } from "./DesignFramework";
import { cloneDeep } from "../shared";
import { SchemaFieldContext } from "../core/SchemaField";

const useDesignActions = () => {
  const { currentDesign } = useContext(DesignFrameworkContext);
  const { setItems, items } = useContext(SchemaFieldContext);

  const updateDesign = () => {
    // @ts-ignore
    window.items = items;
    setItems({...items});
  };

  const addMaterialToDesigner = (schema) => {
    items.properties['x-component-props']['items'].push(schema)
    setItems({...items})
    
};
// const moveMaterial = (sourceKey:string,targetKey:)=>{

// }
const copyMaterialToDesigner = () => {
  
   const item  =  cloneDeep(currentDesign)
   
   items.push(item)
   setItems({...items})
   
};
  return {
    updateDesign,
    addMaterialToDesigner,
    copyMaterialToDesigner
  };
};
export default useDesignActions;
